
Ext.define("ZO0.util.MyCheckColumn", {
    extend: 'Ext.grid.column.CheckColumn',
    alias: 'widget.mychclmn',

    constructor: function() {
        //console.info('constructor arguments=',arguments);
        this.callParent(arguments);
    },
    processEvent: function(type, view, cell, recordIndex, cellIndex, e, record, row) {
        //console.info('processEvent type=',type,' view=',view,' cell=',cell,' recordIndex=',recordIndex,' cellIndex=',cellIndex,' record=',record,' row=',row);
        var me = this,
            key = type === 'keydown' && e.getKey(),
            mousedown = type === 'mousedown';

        if(!me.disabled && (mousedown || (key === e.ENTER || key === e.SPACE))) {
            var dataIndex = me.dataIndex,
                checked = !record.get(dataIndex);

            // Allow apps to hook beforecheckchange
            if(me.fireEvent('beforecheckchange', me, recordIndex, checked) !== false) {
                //console.info(' recordIndex=',recordIndex,' record.data[dataIndex]=',isNaN(record.data[dataIndex]),' checked=',checked);
                if(isNaN(record.data[dataIndex])) {
                    return false;
                }
                record.set(dataIndex, checked);
                me.fireEvent('checkchange', me, recordIndex, checked);

                // Mousedown on the now nonexistent cell causes the view to blur, so stop it continuing.
                if(mousedown) {
                    e.stopEvent();
                }

                // Selection will not proceed after this because of the DOM update caused by the record modification
                // Invoke the SelectionModel unless configured not to do so
                if (!me.stopSelection) {
                    view.selModel.selectByPosition({
                        row: recordIndex,
                        column: cellIndex
                    });
                }

                // Prevent the view from propagating the event to the selection model - we have done that job.
                return false;
            } else {
                // Prevent the view from propagating the event to the selection model if configured to do so.
                return !me.stopSelection;
            }
        } else {
            return me.callParent(arguments);
        }
    },
    renderer: function(value, meta) {
        //console.info('renderer value=',value,' meta=',meta,' NaN=',isNaN(value));
        if(isNaN(value)) {
            return '&#160;';
        }
        var cssPrefix = Ext.baseCSSPrefix,
            cls = [cssPrefix + 'grid-checkcolumn'];

        if(this.disabled) {
            meta.tdCls += ' ' + this.disabledCls;
        }
        if(value) {
            cls.push(cssPrefix + 'grid-checkcolumn-checked');
        }
        return '<img class="' + cls.join(' ') + '" src="' + Ext.BLANK_IMAGE_URL + '"/>';
    }
});
